#include "frame.h"
#include "frame_control.h"
#include "frame_drive.h"
#include "frame_state.h"
#include "qtmetamacros.h"
#include <stdexcept>
Frame::Frame(QObject *parent) : QObject{parent}
{
    this->id = -1;
    this->size = 0;
}

Frame::Frame(qint32 id, qint32 size, QObject *parent) : QObject{parent}
{
    this->id = id;
    this->size = size;
}

Frame::~Frame() {}

qint32 Frame::Id() const
{
    return id;
};
qint32 Frame::Size() const
{
    return size;
};

void Frame::NotifyLocalChange()
{
    emit OnFrameChangedByLocal();
}
void Frame::NotifyRemoteChange()
{
    emit OnFrameChangedByRemote();
}

qint32 Frame::PeekFrameID(const QByteArray &bytes)
{
    return bytes.at(0) >> 24 | (bytes.at(1) >> 16) | (bytes.at(2) >> 8) | (bytes.at(3));
}

QByteArray Frame::WrapFrame(const Frame &frame)
{
    QByteArray bytes;
    bytes.append((frame.Id() >> 24) & 0xff);
    bytes.append((frame.Id() >> 16) & 0xff);
    bytes.append((frame.Id() >> 8) & 0xff);
    bytes.append(frame.Id() & 0xff);
    bytes.append((frame.Size() >> 24) & 0xff);
    bytes.append((frame.Size() >> 16) & 0xff);
    bytes.append((frame.Size() >> 8) & 0xff);
    bytes.append(frame.Size() & 0xff);
    bytes.append(frame.EncodeToBytes());
    return bytes;
}